package com.caption.interceptor;


import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.ThreadContext;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//服务端认证拦截器
@Slf4j
public class AuthenticationInterceptor implements HandlerInterceptor {


    //请求前拦截
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object)  {
        ThreadContext.pop();
        String txnId = request.getHeader("txnId");
        ThreadContext.push(txnId);
        String token = request.getHeader("Authorization");
        log.info("token：{}",token);
        return true;
    }


   //请求时处理
    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }
    //请求后处理
    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}
